import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  }

  //{
  //  path: '/hardware',
  //  component: Layout,
  //  meta: { title: '物联网', icon: 'el-icon-s-help' },
  //  children: [
  //    {
  //      path: 'equipment',
  //      name: 'Equipment',
  //      component: () => import('@/views/hardware/equipment/index'),
  //      meta: { title: '设备列表', icon: 'dashboard' }
  //    },
  //    {
  //      path: 'data',
  //      name: 'Data',
  //      component: () => import('@/views/hardware/data/index'),
  //      meta: { title: '设备数据', icon: 'dashboard' }
  //    }
  //  ]
  //},
  //
  //{
  //  path: '/forms',
  //  component: Layout,
  //  meta: { title: '数据报表', icon: 'el-icon-s-help' },
  //  children: [
  //    {
  //      path: 'chart',
  //      name: 'Chart',
  //      component: () => import('@/views/forms/chart/index'),
  //      meta: { title: '数据图表', icon: 'dashboard' }
  //    },
  //    {
  //      path: 'statistics',
  //      name: 'Statistics',
  //      component: () => import('@/views/forms/statistics/index'),
  //      meta: { title: '数据统计', icon: 'dashboard' }
  //    }
  //  ]
  //},
  //
  //{
  //  path: '/log',
  //  component: Layout,
  //  meta: { title: '日志管理', icon: 'el-icon-s-help' },
  //  children: [
  //    {
  //      path: 'loginLog',
  //      name: 'LoginLog',
  //      component: () => import('@/views/log/loginLog/index'),
  //      meta: { title: '登录日志', icon: 'dashboard' }
  //    },
  //    {
  //      path: 'operationLog',
  //      name: 'OperationLog',
  //      component: () => import('@/views/log/operationLog/index'),
  //      meta: { title: '操作日志', icon: 'dashboard' }
  //    }
  //  ]
  //}

  // {
  //   path: '/system',
  //   component: Layout,
  //   redirect: '/system/sysUser',
  //   name: 'System',
  //   meta: { title: '系统管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'sysUser',
  //       name: 'SysUser',
  //       component: () => import('@/views/system/sysUser/index'),
  //       meta: { title: '用户管理', icon: 'tree' }
  //     },
  //     {
  //       path: 'sysRole',
  //       name: 'SysRole',
  //       component: () => import('@/views/system/sysRole/index'),
  //       meta: { title: '角色管理', icon: 'table' }
  //     },
  //     {
  //       path: 'sysMenu',
  //       name: 'SysMenu',
  //       component: () => import('@/views/system/sysMenu/index'),
  //       meta: { title: '菜单管理', icon: 'tree' }
  //     },
  //     {
  //       path: 'assignAuth',
  //       component: () => import('@/views/system/sysRole/assignAuth'),
  //       meta: {
  //         activeMenu: '/system/sysRole',
  //         title: '角色授权'
  //       },
  //       hidden: true
  //     }
  //   ]
  // },
  //
  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
